package com.lh_travel.lohas.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.lh_travel.lohas.R;
import com.lh_travel.lohas.activity.webview.WebViewActivity;
import com.lh_travel.lohas.adapter.CommonAdapter;
import com.lh_travel.lohas.adapter.ViewHolder;
import com.lh_travel.lohas.base.BaseFragment;
import com.lh_travel.lohas.domain.Comment;
import com.lh_travel.lohas.domain.CommentIntentBean;

import java.math.BigDecimal;
import java.util.ArrayList;

@SuppressLint("ValidFragment")
public class PriceFragment extends BaseFragment {

    private ListView lv_list;
    private ArrayList<Comment> shop;
    private double rate;
    private String checkIn;
    private String checkOut;
    private String title;

    public PriceFragment(ArrayList<Comment> shop, double rate, String checkIn, String checkOut, String title) {



        this.shop = shop;
        this.rate = rate;
        this.checkIn = checkIn;
        this.checkOut = checkOut;
        this.title = title;
    }

    public PriceFragment() {
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_price;
    }

    @Override
    protected void initView() {
        lv_list = findView(R.id.lv_list);

        initRCY();
    }

    private void initRCY() {

        CommonAdapter<Comment> commonAdapter = new CommonAdapter<Comment>(context, shop, R.layout.item_detail_price) {
            @Override
            public void convert(ViewHolder helper, Comment item, int position) {

                helper.setText(R.id.tv_info, item.breakfast + "  " + item.name);
                helper.setImageUrl2(R.id.img, item.picture);
                helper.setText(R.id.tv_price, "¥" + item.third_price);

                final CommentIntentBean bean = new CommentIntentBean();

                bean.keyWord = title;
                bean.checkIn = checkIn.substring(5);
                bean.checkOut = checkOut.substring(5);
                bean.url = item.third_url;
                bean.belong = item.title;

                helper.setViewOnclick(R.id.main, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        Intent intent = new Intent(context, WebViewActivity.class);
                        intent.putExtra("detailBean", bean);
                        intent.putExtra("shop", shop);
                        startActivity(intent);

                        getActivity().overridePendingTransition(R.anim.act_bottom_in, R.anim.act_top_out);

                    }
                });
            }
        };

        if (rate > 0.1) {
            View view = View.inflate(context, R.layout.item_price_hint, null);

            double value = new BigDecimal(rate).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

            int value2 = (int) (value * 100);

            TextView tv_price_hint = view.findViewById(R.id.tv_price_hint);

            tv_price_hint.setText(context.getString(R.string.price_hint1) + value2 + context.getString(R.string.price_hint2));

            lv_list.addHeaderView(view);
        }

        lv_list.setAdapter(commonAdapter);

    }

    @Override
    protected void initData() {

    }
}
